
uniform vec4 inputColor;
uniform float threshold;

varying vec2 textureCoordinate;
uniform sampler2D videoFrame;


void main()
{

   // hipass filter
   vec4 color2 = texture2D(videoFrame, gl_TexCoord[0].st);

   // only let low intensity colors thru
   if(true)
   {
	   // Red paper finder. tuna for rommet
	   
	   color2.r = color2.r > 0.48 ? 1.0 : 0.0;
	   color2.g = color2.g < 0.3 ? 1.0 : 0.0;
	   color2.b = color2.b < 0.3 ? 1.0 : 0.0;
	   
	   
	   /*
	   color2.r = color2.r > 0.2 ? 1.0 : 0.0;
	   color2.g = color2.g < 0.28 ? 1.0 : 0.0;
	   color2.b = color2.b < 0.28 ? 1.0 : 0.0;
	   */
	}
	// only let high intensity colors thru, like red&yellow, not green or blue
   else
   {
	   color2.r = color2.r > 0.3 ? 1.0 : 0.0;
	   color2.g = color2.g > 0.3 ? 1.0 : 0.0;
	   color2.b = color2.b > 0.3 ? 1.0 : 0.0;
   }

   vec4 fOut = vec4(0,0,0,0); 
	
   //if ( color.r > 0.7 && color.g > 0.7 && color.b < 0.60 ) //

   //if ( color.r > 0.65 && color.g > 0.65 && color.b < 0.45 ) // nesten perfekt for gul
   
   //if ( color.r > 0.34 && color.r < 0.5 && color.g > 0.38 && color.b < 0.5 && color.b < 0.33 && color.b < 0.35 )
   
  // if ( color.r < 0.2 && color.g < 0.2 && color.b < 0.02 ) 
   
      
   //if ( color2.r <= 0.2 && color2.g <= 0.2 && color2.b >= 0.9 ) 
   //if ( abs(color2.r-inputColor.r)<0.3 &&  abs(color2.g-inputColor.g)<0.3 &&  abs(color2.b-inputColor.b)<0.3 ) 
   
   if( color2.r >= 1.0 && color2.g >= 1.0 && color2.b >= 1.0)
   {
	//fOut = vec4(1.0-gl_TexCoord[0].s,1.0-gl_TexCoord[0].t,1,1);  //output blue when area to track
   fOut = vec4(1,1,1,1);  //output blue when area to track
   }else
   {
	fOut = vec4(0,0,0,1); // output zero when no area to track
   }


   //gl_FragColor = fOut;
   
   gl_FragColor = color2; 
   
   //gl_FragColor = texture2D(videoFrame, gl_TexCoord[0].st );

 
   
}


/*
void main()
 {
     vec4 sample[9];

    for (int i = 0; i < 9; i++)
    {
        sample[i] = texture2D(videoFrame, 
                              gl_TexCoord[0].st + tc_offset[i]);
    }

//   1 1 1
//   1 1 1   / 13
//   1 1 1

	float weight = 1.0;

    vec4 sumColor = (weight*sample[0] + (weight*1.0*sample[1]) + weight*sample[2] + 
                    (weight*1.0*sample[3]) + weight*sample[4] + (weight*1.0*sample[5]) + 
                    weight*sample[6] + (weight*1.0*sample[7]) + weight*sample[8]) /13.0;
		
	vec4 compareColor = inputColor;
	compareColor.r -= 0.01;
	compareColor.g -= 0.01;
	compareColor.b += 0.01;
	
	// color.r > 0.6 && color.g > 0.6 && color.b < 0.45
	//if( sumColor.r > inputColor.r && sumColor.g > inputColor.g && sumColor.b > inputColor.b) //  || sumColor.b > 0.9
	
	if( sumColor.r >= compareColor.r && sumColor.g >= compareColor.g && sumColor.b <= compareColor.b && sumColor.b > 0.3)
	{
		gl_FragColor = vec4(1,0,0,1);
	}
	else
	{
		//gl_FragColor = vec4(1,1,0,1);
		gl_FragColor = texture2D(videoFrame, gl_TexCoord[0].st);
	}
 }
*/